package com.project.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.bean.MouseBean;
import com.project.service.MouseService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
@RequestMapping("mouse")
public class MouseController {

    @Resource
    private MouseService mouseService;

    //显示所有鼠害信息
    @RequestMapping("findAllMouse")
    @ResponseBody
    public IPage<MouseBean> findAllMouse(@RequestParam(value = "pageNo", defaultValue = "1") int pageNo,
                                         @RequestParam(value = "pageSize", defaultValue = "3") int pageSize) {
        return mouseService.findAllMouse(pageNo, pageSize);
    }


    //添加新鼠害
    @RequestMapping("addMouse")
    @ResponseBody
    public String addMouse(MouseBean mouseBean) {
        mouseService.addMouse(mouseBean);
        return "ok";
    }


    //查看详细信息
    @RequestMapping("findId")
    @ResponseBody
    public MouseBean findId(int mouseId) {
        return mouseService.findId(mouseId);
    }


    //模糊查询
    @RequestMapping("findName")
    @ResponseBody
    public IPage<MouseBean> findName(@RequestParam(value = "pageNo", defaultValue = "1") int pageNo,
                                     @RequestParam(value = "pageSize", defaultValue = "3") int pageSize,
                                     String mouseName) {
        return mouseService.findName(pageNo, pageSize, mouseName);
    }
}
